package com.gxa.learning.pc.controller;

import com.github.pagehelper.PageInfo;
import com.gxa.learning.core.common.ExceptionCode;
import com.gxa.learning.core.common.JsonResult;
import com.gxa.learning.core.exception.BusinessException;
import com.gxa.learning.pc.service.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.Map;

/**
 * @author lijianmin
 * @date 2021/12/11  14:24:24
 */
@RestController
@RequestMapping("/msg")
@Api(tags = "PC端我的考试的接口")
public class MessageController {

    @Autowired
    private MessageService messageService;

    /**
     * 获取当前用户的所有考试的接口
     *
     * @return 返回找到列表
     */
    @GetMapping("/getExam")
    @ApiOperation("获取当前用户的所有考试的接口")
    @ApiImplicitParam(name = "id", value = "用户编号", paramType = "query")
    public Map<String, Object> getExamList(@RequestParam("id") Long id) throws BusinessException, ParseException {
        if (id == null) {
            throw new BusinessException(ExceptionCode.ARGUMENTS_NOT_NULL);
        }
        PageInfo<Map<String, Object>> mapPageInfo = messageService.selectUserTest(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.put("count", mapPageInfo.getTotal());
        jsonResult.setData(mapPageInfo.getList());
        jsonResult.setMsg("查询成功");
        return jsonResult.getDataMap();
    }
}
